<!DOCTYPE html>
<html lang="zh-CN">
<head>
 
<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
 
    <script>
    
        jQuery(document).ready(function() 
        {   
            App.init();
            combox("roleId","Role",null,null,false);
            $("#roleId option[value='<#if roleId??>${roleId}</#if>']").attr("selected", true);  
        });

    var parentIndex = 0;
    var editId = 0;
     function addSubMenu(parent_text, index, level) {
     	
 		jConfirm('将在"'+parent_text+'"菜单下增加子菜单', '提示', function(r) {
		    if(r==true){
		        showPopup(parent_text, level);
		         parentIndex = index;
            }
 	    });
     }

    function doEditMenu() {
        var editMenuText=document.getElementById("editMenuText").value;
        var editUrl=document.getElementById("editUrl").value;
        var count = true;

        resetLabel();
        if (editMenuText == null || editMenuText == "") {
        document.getElementById("editMenuText").style.borderColor = "#FF0000";
        count=false;
        }

        if (count) {
        $("#postaction3").val("edit");
        $("#editId").val(editId);
        $("#editForm").submit();
        }
    }

    function doAddMenu() {
        var addMenuText=document.getElementById("addMenuText").value;
        var addParentText=document.getElementById("addParentText").value;
        var addUrl=document.getElementById("addUrl").value;
        var addLevel=document.getElementById("addLevel").value;
        var addIcon=document.getElementById("addIcon").value;
        var addMinRoleLevel=document.getElementById("addMinRoleLevel").value;
        var count = true;

        resetLabel();
        if (addMenuText == null || addMenuText == "") {
        document.getElementById("addMenuText").style.borderColor = "#FF0000";
        count=false;
        }
        if (addIcon == null || addIcon == "") {
        document.getElementById("addIcon").style.borderColor = "#FF0000";
        count=false;
        }
        if (addMinRoleLevel == null || addMinRoleLevel == "") {
        document.getElementById("addMinRoleLevel").style.borderColor = "#FF0000";
        count=false;
        }

        if (count) {
        $("#postaction2").val("insert");
        $("#addParentIndex").val(parentIndex);
        $("#addForm").submit();
        }


    }

    function updateMenu() {

        $('#postaction1').val('update');
        $('#trueLeftMenu').val($('#nestable_list_1_output').val());
        $("#searchform").submit();
    }

    function resetLabel() {
        $("#insertdlg input").each(function(index, element)
        {
        $(this).css('borderColor','#BBB');
        });
        $("#editdlg input").each(function(index, element)
        {
        $(this).css('borderColor','#BBB');
        });
    }

    function showEditDiv(url, text) {//弹出层
        var backDiv =$("#backDiv");
        backDiv.css('top','0%');
        backDiv.css('left','0%');
        backDiv.css('width','100%');
        backDiv.css('height','100%');
        backDiv.css('visibility','visible');

        realDiv.css('top','30%');
        realDiv.css('left','30%');
        realDiv.css('width','40%');
        realDiv.css('height','auto');
        realDiv.css('visibility','visible');

        document.getElementById("editMenuText").value = text;
        document.getElementById("editUrl").value = url;
    }

    function showPopup(parent_text, level) {//弹出层
        var backDiv =$("#backDiv");
        backDiv.css('top','0%');
        backDiv.css('left','0%');
        backDiv.css('width','100%');
        backDiv.css('height','100%');
        backDiv.css('visibility','visible');

//        var realDiv =$("#"+div);
        var realDiv =$("#realDiv");
        realDiv.css('top','30%');
        realDiv.css('left','30%');
        realDiv.css('width','40%');
        realDiv.css('height','auto');
        realDiv.css('visibility','visible');

        document.getElementById("addParentText").value = parent_text;
        document.getElementById("addLevel").value = parseInt(level)+1;
    }

    function hidePopup() {//关闭层
        $("#insertdlg input").each(function(index, element)
        {
        $(this).val(null);
        $(this).css('borderColor','#BBB');
        });
        $("#editdlg input").each(function(index, element)
        {
        $(this).val(null);
        $(this).css('borderColor','#BBB');
        });

        resetLabel();
        var backDiv = document.getElementById("backDiv");
        backDiv.style.visibility = "hidden";

        var realDiv = document.getElementById("realDiv");
        realDiv.style.visibility = "hidden";

        var editDiv = document.getElementById("editDiv");
        editDiv.style.visibility = "hidden";
    }

    function allDivHide() {
        hidePopup();
//        hideEditTable();
    }

    function deleteMenu(id, text) {
    	jConfirm('确定删除"' + text + '?', '提示', function(r) {
			  if(r==true){
		        $('#postaction1').val('delete');
		        $('#postarg').val(id);
		        $("#searchform").submit();
		      }
    	});
    }

    function editMenu(id, url, text) {
        showEditDiv(url, text);
        editId = id;
        $("#oldUrl").val(url);
    }

    function submitChosenBox() {
        var checknum=document.getElementsByName("ids").length;
        var str="";
        if (checknum==0) {
        	jAlert("请至少选择一个菜单项");
        return;
        }
        for(var i=0;i<checknum;i++){
        if(document.getElementsByName("ids")[i].checked==true){
            str = str+'&id'+i+'='+document.getElementsByName("ids")[i].value;
        }
        }
        console.log(str);
        $("#loading").showLoading(); 
        $.getJSON(
            "dispose_menu?roldId="+$('#roleId option:selected').val()+str,
            function(data){
            	 $('#loading').hideLoading();
            	 jAlert(data);
            });
    }

    </script>
</head>

<body>


<#include "bases/navhead.ftl">
<#include "bases/sidebar.ftl">

    <div class="page-container secMenu-content" id="loading">    
 
     
        <div class="page-content">
     
            <div class="container-fluid">

                <div class="row-fluid">
                    <div class="span12">
                        <div class="portlet box green">
                            <div class="portlet-title">
                                <div class="caption"><i class="fa fa-cogs"></i>权限管理</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
                            </div>
                            <div class="portlet-body flip-scroll">
                                                            
                            <form id="searchform" action="<@spring.url '/left_menu_role_manage'></@spring.url>" method="POST">
					                <input  type="hidden" id="postaction1" name="postaction" />
					                <input  type="hidden" id="postarg" name="postarg" />
 
									<div class="controls controls-row" >
					                    <label class="roleId">角色：</label>
					                    <select id="roleId" name="roleId" style="height: 35px"  class="sheet-searchInput" onchange="$('#searchform').submit()" value="<#if roleId?exists>${roleId}<#else>5</#if>">
					                    </select>
					                    <button type="button" class="btn blue" data-action="expand-all" onclick="javascript:$('.dd').nestable('expandAll');">全部展开</button>
					                    <button type="button" class="btn blue" data-action="collapse-all" onclick="javascript:$('.dd').nestable('collapseAll');">全部收起</button>
					                    <#if left_menu_list?exists><button type="button" class="btn blue" onclick="submitChosenBox()"></i>提交</button></#if>
					                </div>
					
					
					                <div class="controls controls-row">
					                    <input type="hidden" id="nestable_list_1_output" class="m-wrap span12"></textarea>
					                    <input type="hidden" id="trueLeftMenu" name="newLeftMenu" class="m-wrap span12"/>
					                </div>
                                    <!-- 显示菜单树 begin -->
					                <div class="portlet-body ">
					                    <div class="dd" id="nestable_list_1">
					                    <ol class="dd-list">
					                        <#list left_menu_list as sbl>
					                        <li class="dd-item dd3-item"data-id="${sbl.getId()}">
					                            <div class="dd-handle dd3-handle"></div>
					                            <div class="dd3-content" >
					                            <#if sbl.getRoleApproved()?exists>
					                                <input name="ids" type="checkbox" checked="true" value="${sbl.getId()}" style="float:left;"/>
					                            <#else>
					                                <input name="ids" type="checkbox" value="${sbl.getId()}" style="float:left;"/>
					                            </#if>
					                            <#--<input name="ids" checked="<#if sbl.getRoleApproved()?exists><#if sbl.getRoleApproved()>true</#if></#if>"  type="checkbox" value="${sbl.getId()}" style="float:left;"/>-->
					                            ${sbl.getText()}
					                            </div>
					                            <#if !sbl.hasSubMenu()>
					                            <ol class="dd-list">
					                                <#assign level2menus = sbl.getSubmenus()/>
					                                <#list level2menus as level2>
					                                <li class="dd-item dd3-item" data-id="${level2.getId()}">
					                                    <div class="dd-handle dd3-handle"></div>
					                                    <div class="dd3-content">
					                                    <#if level2.getRoleApproved()?exists>
					                                        <input name="ids" type="checkbox" checked="true" value="${level2.getId()}" style="float:left;"/>
					                                    <#else>
					                                        <input name="ids" type="checkbox" value="${level2.getId()}" style="float:left;"/>
					                                    </#if>
					                                    <#--<input name="ids" checked="<#if level2.getRoleApproved()?exists><#if sbl.getRoleApproved()>true</#if></#if>"  type="checkbox" value="${level2.getId()}" style="float:left;"/>-->
					                                    ${level2.getText()}
					                                    </div>
					                                    <#if !level2.hasSubMenu()>
					                                    <ol class="dd-list">
					                                        <#assign level3menus = level2.getSubmenus()/>
					                                        <#list level3menus as level3>
					                                        <li class="dd-item dd3-item" data-id="${level3.getId()}">
					                                            <div class="dd-handle dd3-handle"></div>
					                                            <div class="dd3-content">
					                                            <#if level3.getRoleApproved()?exists>
					                                                <input name="ids" type="checkbox" checked="true" value="${level3.getId()}" style="float:left;"/>
					                                            <#else>
					                                                <input name="ids" type="checkbox" value="${level3.getId()}" style="float:left;"/>
					                                            </#if>
					                                            <#--<input name="ids" checked="<#if level3.getRoleApproved()?exists>true<#else>false</#if>"  type="checkbox" value="${level3.getId()}" style="float:left;"/>-->
					                                            ${level3.getText()}
					                                            </div>
					                                        </li>
					                                        </#list>
					                                    </ol>
					                                    </#if>
					                                </li>
					                                </#list>
					                            </ol>
					                            </#if>
					                        </li>
					                        </#list>
					                    </ol>
					                    </div>
					                </div>
                                <div  class="controls controls-row">
                                <div id="Pagination" class="pagination"></div>
                                </div>
                                 </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
      </div>
 
</body>

</html>




